package jnzb.ui.queue;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

import jnzb.JNZB;
import jnzb.control.Controller;

public class QueueFrame extends JFrame {

	private JPanel mainPanel;
	private QueueControlPanel queuePanel;
	private FinishedPanel finishedPanel;

	public QueueFrame() {
		create();
	}

	public void registerListeners(Controller controller){
		this.queuePanel.registerListeners(controller);
	}
	private void create() {
		// just hide when closed
		this.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

		this.setTitle("jNZB " + JNZB.VERSION + " - Queue");

		this.setResizable(true);

		// Create the panel with the search and results displays on
		this.add(createMainPanel());

		this.queuePanel = new QueueControlPanel();
		this.mainPanel.add(queuePanel);

		this.finishedPanel = new FinishedPanel();
		this.mainPanel.add(finishedPanel);

		// Locate components relative to each other
		this.pack();
		// Centre on the screen - important this is done after the pack()
		this.setLocationRelativeTo(null);

	}

	/**
	 * Creates the top level panel
	 * 
	 * @return
	 */
	private Component createMainPanel() {
		this.mainPanel = new JPanel();
		this.mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

		// Add some padding as an empty border
		this.mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));

		return mainPanel;
	}
	
	public QueueControlPanel getQueueControlPanel(){
		return this.queuePanel;
	}
	
	public FinishedPanel getFinishedPanel(){
		return this.finishedPanel;
	}
}
